package com.kgc.sbt.provider;

import com.alibaba.dubbo.config.annotation.Service;
import com.kgc.sbt.api.CouponLogsApi;
import com.kgc.sbt.domain.CouponLogs;
import com.kgc.sbt.mapper.CouponLogsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

import java.util.Date;

/**
 * @author Shan
 * @date 2021/6/22
 * @return
 * @description 优惠券使用记录
 */
@Service
@Slf4j
public class CouponLogsProvider implements CouponLogsApi {

    @Autowired
    private CouponLogsMapper couponLogsMapper;

    @Async
    @Override
    public void insertCouponLogs(Integer userId, Integer couponId, String orderNumber) {
        CouponLogs couponLogs = new CouponLogs();
        //用户id
        couponLogs.setUserId(userId);
        //优惠券id
        couponLogs.setCouponId(couponId);
        //订单号
        couponLogs.setOrderNumber(orderNumber);
        couponLogs.setCreateTime(new Date());
        couponLogs.setStatus(0);

        if (couponLogsMapper.insert(couponLogs) == 1) {
            log.error("优惠券消费记录异步执行完成！");
        }

    }
}
